#include<iostream>
#define MVNum 100
#define OK 1
#define ERROR -1 

using namespace std;
typedef char verTexType;//顶点的数据类型 
typedef int status;
char v1, v2;

typedef struct ArcNode//边结点 
{
	int adjvex;	//边所指向的顶点信息 
	struct ArcNode * nextarc;//指向下一条的指针 
	int info;//	 与边相关的信息 
}ArcNode; 

//顶点信息 
typedef struct VNode{
	verTexType data; 
	ArcNode *firstarc; //指向第一条依附该顶点的边的指针 
}VNode,AdjList[MVNum];

//链接表 
typedef struct{
	AdjList vertices;
	int vexnum,arcnum;
}ALGraph;

//函数声明 
status createUDG(ALGraph &G);
int LocateVex(ALGraph G, verTexType v);
void PrintGraph(ALGraph G);

int main()
{
	ALGraph G; 
	createUDG(G);
	PrintGraph(G);
	return 0;
}

status createUDG(ALGraph &G)
{
	//采用邻接表表示
	cout << "输入总顶点数和总边数" << endl;
	cin >> G.vexnum >> G.arcnum;
	cout << "输入顶点值" << endl;
	for(int i = 0; i < G.vexnum; ++i)
	{
		cin >> G.vertices[i].data;
		G.vertices[i].firstarc = NULL;
	}
	cout << "输入一条边依附的两个顶点" << endl;
	for(int k = 0; k < G.arcnum; ++k)
	{
		cin >> v1 >> v2;
		int i = LocateVex(G, v1);
		int j = LocateVex(G, v2);
		ArcNode *p1 =new ArcNode;
		p1->adjvex = j;
		p1->nextarc = G.vertices[i].firstarc;
		G.vertices[i].firstarc = p1;
		ArcNode *p2 =new ArcNode;
		p2->adjvex = i;
		p2->nextarc = G.vertices[j].firstarc;
		G.vertices[j].firstarc = p2;
	}
	return OK;
}

int LocateVex(ALGraph G, verTexType v){
	for(int i = 0; i<G.vexnum; ++i)
		if(v == G.vertices[i].data)
			return i;
	return -1;
}

void PrintGraph(ALGraph G){  
	cout << "该图的邻接表为：" << endl; 
	for(int i = 0; i < G.vexnum; i++){
		cout << i << "|" << G.vertices[i].data << "|";
		ArcNode *p = G.vertices[i].firstarc;
		while(p != NULL){
			cout << "->" << p->adjvex;
			p = p->nextarc;
		}
		cout << "^";
		cout << endl;
	}
	cout << endl;
}